package day07test;

import java.sql.SQLOutput;
import java.util.Random;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            String code = code(5);
            System.out.println(code);
            System.out.println("请输入验证码");
            String inputCode = sc.next();
            if(inputCode.equalsIgnoreCase(code)){
                System.out.println(true);
                break;
            }
        }

    }

    public static String code(int len) {
        char[] code = new char[len];
        char[] arr = new char[62];
        int a = 97;
        int A = 65;
        int zero = 48;
        for (int i = 0; i < arr.length; i++) {
            if (i < 26) {
                arr[i] = (char) a;
                a++;
            } else if (i >= 26 && i < 52) {
                arr[i] = (char) A;
                A++;
            } else {
                arr[i] = (char) zero;
                zero++;
            }
        }
        Random r = new Random();
        for (int i = 0; i < code.length; i++) {
            int index = r.nextInt(62);
            code[i] = arr[index];
        }
        String result = new String(code);
        return result;
    }
}
